<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <base href="<%=basePath%>">
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript">
var xmlhttp;
function checkloginname(){
	
	var loginname=document.getElementById("useLoginName").value;
	var id=document.getElementById("useId").value;
	if(loginname==""){
		document.getElementById("spnloginname").innerHTML="请输入登录名";
		document.getElementById("spnloginname").style.color="red";
		return false;
	}
	document.getElementById("spnloginname").innerHTML="";
	
	xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=chloginname;

	xmlhttp.open("get","UserServlet?param=ajaxloginname&id="+id+"&loginname="+loginname+"&time="+new Date().getTime(), true);

	xmlhttp.send(null);
}

function chloginname(){
	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		var txt=xmlhttp.responseText;
		document.getElementById("spnloginname").innerHTML=txt;
		if(txt=="√"){
			document.getElementById("spnloginname").style.color="green";
		}else{
			document.getElementById("spnloginname").style.color="red";
		}
	}
	
}

function cklogname(){
    if(document.getElementById("useLoginName").value==""){
    	document.getElementById("spnloginname").innerHTML="请输入登录名";
		document.getElementById("spnloginname").style.color="red";
    	return false; 
    }
   
    document.getElementById("spnloginname").innerHTML="";
	return true;
	
}
function ckpassword(){
	var newpwd=document.getElementById("usePassWord").value;
	if(document.getElementById("usePassWord").value==""){
		document.getElementById("s1").innerHTML="请输入密码";
		document.getElementById("s1").style.color="red";
		return false;
	}else{
		if(newpwd.length<6){
			document.getElementById("s1").innerHTML="弱";
			document.getElementById("s1").style.color="red";
		}else if(newpwd.length>6&&newpwd.length<10){
			document.getElementById("s1").innerHTML="中";
			document.getElementById("s1").style.color="red";
		}else if(newpwd.length>10){
			document.getElementById("s1").innerHTML="强";
			document.getElementById("s1").style.color="red";
		}
		return true;
		
	}
	
	return true;
	
}
function checkname(){
	if(document.getElementById("useName").value==""){
		document.getElementById("s2").innerHTML="请输入姓名";
		document.getElementById("s2").style.color="red";
		return false;
	}
	document.getElementById("s2").innerHTML="";
	return true;
}
function checkidcard(){
	var idcard=document.getElementById("useIdCard").value;
	if(idcard==""){
		document.getElementById("s3").innerHTML="请输入身份证号";
		document.getElementById("s3").style.color="red";
		return false;
	}
	var card= /^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2016)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/;                          
	if(!card.test(idcard)){
		document.getElementById("s3").innerHTML="请输入正确的身份证号";
		document.getElementById("s3").style.color="red";
		return false;
	}
//	alert(idcard.charAt(16)%2);
	if(idcard.charAt(16)%2==0){
		document.getElementById("usesex1").checked=true;
	}else{
		document.getElementById("usesex2").checked=true;
	}
	document.getElementById("s3").innerHTML="";
	
	return true;
}

function checakPhone(){
	
	var phone=document.getElementById("usePhone").value;
	
	if(phone==""){
		document.getElementById("s4").innerHTML="请输入手机号";
		document.getElementById("s4").style.color="red";
		return false;
	}
	var tel= /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|17[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
	if(!tel.test(phone)){
		document.getElementById("s4").innerHTML="请输入正确的手机号";
		document.getElementById("s4").style.color="red";
		return false;
	}
	document.getElementById("s4").innerHTML="";

	return true;
}
function checkaddress(){
	if(document.getElementById("useAddress").value==""){
		document.getElementById("s5").innerHTML="请输入地址";
		document.getElementById("s5").style.color="red";
		return false;
	}
	document.getElementById("s5").innerHTML="";

	return true;
}

function checkemail(){
	var email=document.getElementById("useEmail").value;
	if(email==""){
		document.getElementById("s6").innerHTML="请输入邮箱";
		document.getElementById("s6").style.color="red";
		return false;
	}
	var ema=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(!ema.test(email)){
		document.getElementById("s6").innerHTML="请输入正确的邮箱";
		document.getElementById("s6").style.color="red";
		return false;
	}
	document.getElementById("s6").innerHTML="";
	
	return true;
}
function ckspan(){
	var spa=document.getElementById("spnloginname").innerHTML;
	if(spa=="对不起！该用户名已被占用！"){
		alert("对不起！该用户名已被占用！");
		return false;
	}
	return true;
}
function save(){

	/*表单验证
	*/
	if(ckpassword()&&ckspan()&& cklogname()&&checkname()&&checkidcard()&&checakPhone()&&checkaddress()&&checkemail()){
		if(confirm("保存信息？")){
			document.getElementById("form2").submit();
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
	
	

}

</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td style="height:25px; background-color:#f3f3f3; font-weight:bold" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置：
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;用户管理
    </td>
  </tr>
  <tr>
    <td style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20" height="34"><img src="houtai/images/main_headerL.gif" width="20" height="34"></td>
          <td style="color:#90c8e8;"><img src="houtai/images/icon_card.gif" width="16" height="16" align="absmiddle">&nbsp;&nbsp;<strong>修改用户信息</strong></td>
          <td align="right" class="white" style="padding-right:20px">
          <a class="barBtn" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a>
          <a  class="barBtn" onClick="javascript:history.go(+1);"><img src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a>
          <a href="javascript:history.go(0);" class="barBtn"><img src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="100%" valign="top">
    <div style="overflow:auto;height:100%; width:100%">
    <form id="form2" action="<%=request.getContextPath() %>/UserServlet?param=editByAdmin" method="post" >
      <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
        <TR>
        <input type="hidden" name="useId" id="useId" value="${requestScope.userById.useId }"/>
          <th width="20%" align="center">用户登录名</th>
          <TD class="BGCgray"><input type="text" name="useLoginName" id="useLoginName" onblur="checkloginname()" value="${requestScope.userById.useLoginName }"/><span id="spnloginname"></span></TD>
          </TR>
        <TR>
          <th align="center">密码</th>
          <TD width="80%" class="BGCgray"><input name="usePassWord" type="text" onblur="ckpassword()" id="usePassWord" value="${requestScope.userById.usePassWord }"><span id="s1"></span></TD>
          </TR>
        <TR>
          <th align="center"><span class="BGCgray">真实姓名</span></th>
          <TD class="BGCgray"><input name="useName" type="text" id="useName" onblur="checkname()" value="${requestScope.userById.useName }"/><span id="s2"></span></TD>
        </TR>
		<TR>
          <th align="center"><span class="BGCgray">身份证</span></th>
          <TD class="BGCgray"><input name="useIdCard" type="text" id="useIdCard" onblur="checkidcard()" value="${requestScope.userById.useIdCard }"/><span id="s3"></span></TD>
        </TR>
        <TR>
          <th align="center">性别</th>
          <TD class="BGCgray"> 
          <input type="radio" name="sex" id="usesex2" value="1" ${requestScope.userById.useSex==1?"checked='checked'":"" }/>男<input type="radio" name="sex" id="usesex1" value="0" ${requestScope.userById.useSex==0?"checked='checked'":"" }/>女
          </TD>
        </TR>
        <TR>
          <th align="center">联系电话</th>
          <TD class="BGCgray"><input name="usePhone" type="text" id="usePhone" onblur="checakPhone()" value="${requestScope.userById.usePhone}"/><span id="s4"></span></TD>
        </TR>
        <TR>
          <th align="center">地址</th> 
          <TD class="BGCgray"><input name="useAddress" type="text" id="useAddress" onblur="checkaddress()" value="${requestScope.userById.useAddress }"/><span id="s5"></span></TD>
        </TR>
        <TR>
          <th align="center">邮箱</th>
          <TD class="BGCgray"><input name="useEmail" type="text" id="useEmail" onblur="checkemail()" value="${requestScope.userById.useEmail }"><span id="s6"></span></TD>
        </TR>
	<TR>
          <th align="center">角色</th>
          <TD class="BGCgray"><select name="role">
          <c:forEach items="${requestScope.roles }" var="r">
          		<c:if test="${r.rolState==1&&r.rolDelete==1 }">
		         <option value="${r.rolId }" ${r.rolId==requestScope.userById.role.rolId?"selected='selected'":"" }>${r.rolName }</option>
		         </c:if>
		</c:forEach>
	</select></TD>
        </TR>
        <TR>
          <th align="center">状态</th>
          <TD class="BGCgray"><select name="useState" id="select">
            <option value="1" ${requestScope.userById.useState==1?"selected='selected'":"" }>启用</option>
            <option value="0" ${requestScope.userById.useState==0?"selected='selected'":"" }>禁用</option>
          </select></TD>
        </TR>
      </table>
        </form>
      <div style="width:100%; text-align:center; padding:5px">
        <BUTTON style="HEIGHT:25px" onClick="return save();"><img src="houtai/images/btn_edit.gif" width="16" height="16" align="absmiddle"> 保存</BUTTON>
        <BUTTON style="HEIGHT:25px" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回</BUTTON>
      </div>
    </div>
  
  </td>
  </tr>
</table>
</body>
</html>